package com.inossem.warehousestorage_inossem.utils;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.google.gson.Gson;
import com.inossem.utils.base.Utils;
import com.inossem.utils.constant.UtilsConstant;
import com.inossem.utils.listener.NoDoubleClickListener;
import com.inossem.warehousestorage_inossem.R;
import com.inossem.warehousestorage_inossem.activity.base.BaseActivity;
import com.inossem.warehousestorage_inossem.adapter.OverviewAdapter;
import com.inossem.warehousestorage_inossem.bean.inStorage.InStorageFreeConfirmRequestBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.InStorageFreeOverviewBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.InStorageOtherBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.InStorageOtherConfirmRequestBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.InStorageOtherMaterielOverviewBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.InStorageReceiveConfirmRequestBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.InStorageReceiveOverviewBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.InStorageTenderConfirmRequestBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.InStorageTenderOverviewBean;
import com.inossem.warehousestorage_inossem.dialog.DialogUtils;
import com.jzxiang.pickerview.TimePickerDialog;
import com.jzxiang.pickerview.data.Type;
import com.jzxiang.pickerview.listener.OnDateSetListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by leij on 2017/7/5.
 */

public class InStorageUtils {

    private static final String TYPE_EDITTEXT = "0";

    private static final String TYPE_TIME = "1";

    private static final String TYPE_SPINNER = "2";

    private static final String REQUIRED_TRUE = "1";

    private static final String REQUIRED_FALSE = "2";

    private static final String IS_FOCUS_TRUE = "1";  //允许修改过账日期

    private static final String IS_FOCUS_FALSE = "0";//不允许修改过账日期

    public static final int NO_BATCH = -1;//没有批次信息

    public static final int BATCH_NO_MESSAGE = 0;//批次信息无信息

    public static final int BATCH_HAS_MESSAGE = 1;//批次信息有信息

    public static final int BATCH_NO_MESSAGE_BUT_REQUIRED = 2;//批次信息无信息,但是必填

    public static int checkReceiveBatchInfo(Context context) {
        int result = -1;
        List<InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean> receiveInStorageList = getInStorageReceiveOverviewBean(context).getData().getReceiveInStorageList();
        if (receiveInStorageList != null && !receiveInStorageList.isEmpty()) {
            for (int i = 0; i < receiveInStorageList.size(); i++) {
                InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean receiveInStorageItem = receiveInStorageList.get(i);
                List<InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean.BatchBean> batchList = receiveInStorageItem.getBatch();
                for (int j = 0; j < batchList.size(); j++) {
                    InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean.BatchBean batchBean = batchList.get(j);
//                    LogUtils.i("Name:" + batchBean.getName() + "---Text:" + batchBean.getText() + "---Value:" + batchBean.getValue());
                    if (REQUIRED_TRUE.equals(batchBean.getRequired())) {
                        if (TextUtils.isEmpty(batchBean.getText()) && TextUtils.isEmpty(batchBean.getValue())) {
                            result = i + 1;
                            return result;
                        }
                    }
                }
            }
        }
        return result;
    }

    public static int checkFreeBatchInfo(Context context) {
        int result = -1;
        List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean> list = getInStorageFreeOverviewBean(context).getData().getFreeInStorageList();
        for (int i = 0; i < list.size(); i++) {
            InStorageFreeOverviewBean.DataBean.FreeInStorageListBean freeInStorageItem = list.get(i);
            List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean.BatchBean> batchList = freeInStorageItem.getBatch();
            for (int j = 0; j < batchList.size(); j++) {
                InStorageFreeOverviewBean.DataBean.FreeInStorageListBean.BatchBean batchBean = batchList.get(j);
                if (REQUIRED_TRUE.equals(batchBean.getRequired())) {
                    if ("".equals(batchBean.getText()) && "".equals(batchBean.getValue())) {
                        result = i + 1;
                        return result;
                    }
                }
            }
        }
        return result;
    }

    public static int checkOtherBatchInfo(Context context) {
        int result = -1;
        List<InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean> list = getInStorageOtherBean(context).getMaterielList();
        for (int i = 0; i < list.size(); i++) {
            InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean otherInStorageItem = list.get(i);
            List<InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean.BatchBean> batchList = otherInStorageItem.getBatch();
            for (int j = 0; j < batchList.size(); j++) {
                InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean.BatchBean batchBean = batchList.get(j);
                if (REQUIRED_TRUE.equals(batchBean.getRequired())) {
                    if ("".equals(batchBean.getText()) && "".equals(batchBean.getValue())) {
                        result = i + 1;
                        return result;
                    }
                }
            }
        }
        return result;
    }

    public static int checkFreeInStorageNumber(Context context) {
        int result = -1;
        List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean> list = getInStorageFreeOverviewBean(context).getData().getFreeInStorageList();
        for (int i = 0; i < list.size(); i++) {
            InStorageFreeOverviewBean.DataBean.FreeInStorageListBean freeInStorageItem = list.get(i);
            if (TextUtils.isEmpty(freeInStorageItem.getInStorageNumber())) {
                result = i + 1;
                return result;
            }
        }
        return result;
    }

    //获取免检入库可提交行项目数量
    public static int getFreeInStorageConfirmNumber(Context context) {
        int result = 0;
        List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean> list = getInStorageFreeOverviewBean(context).getData().getFreeInStorageList();
        if (list == null) {
            return result;
        } else {
            for (int i = 0; i < list.size(); i++) {
                InStorageFreeOverviewBean.DataBean.FreeInStorageListBean freeInStorageItem = list.get(i);
                if (!TextUtils.isEmpty(freeInStorageItem.getInStorageNumber())) {
                    result = result + 1;
                }
            }
        }
        return result;
    }

    //获取招采入库可提交行项目数量
    public static int getTenderInStorageConfirmNumber(Context context) {
        int result = 0;
        List<InStorageTenderOverviewBean.DataBean.FreeInStorageListBean> list = getInStorageTenderOverviewBean(context).getData().getFreeInStorageList();
        if (list == null) {
            return result;
        } else {
            for (int i = 0; i < list.size(); i++) {
                InStorageTenderOverviewBean.DataBean.FreeInStorageListBean freeInStorageItem = list.get(i);
                if (!TextUtils.isEmpty(freeInStorageItem.getInStorageNumber())) {
                    result = result + 1;
                }
            }
        }
        return result;
    }

    public static int getOtherInStorageConfirmNumber(Context context) {
        int result = 0;
        List<InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean> list = getInStorageOtherBean(context).getMaterielList();
        if (list == null) {
            return result;
        } else {
            for (int i = 0; i < list.size(); i++) {
                InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean otherInStorageItem = list.get(i);
                if (!TextUtils.isEmpty(otherInStorageItem.getInStorageNumber())) {
                    result = result + 1;
                }
            }
        }
        return result;
    }

//    public static int checkFreeInStorage(Context context) {
//        int result = -1;
//        List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean> list = getInStorageFreeOverviewBean(context).getData().getFreeInStorageList();
//        for (int i = 0; i < list.size(); i++) {
//            InStorageFreeOverviewBean.DataBean.FreeInStorageListBean freeInStorageItem = list.get(i);
//            if (!TextUtils.isEmpty(freeInStorageItem.getInStorageNumber())) {
//                List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean.BatchBean> batchList = freeInStorageItem.getBatch();
//                for (int j = 0; j < batchList.size(); j++) {
//                    InStorageFreeOverviewBean.DataBean.FreeInStorageListBean.BatchBean batchBean = batchList.get(j);
//                    if (REQUIRED_TRUE.equals(batchBean.getRequired())) {
//                        if ("".equals(batchBean.getText()) && "".equals(batchBean.getValue())) {
//                            result = i + 1;
//                            return result;
//                        }
//                    }
//                }
//            }
//        }
//        return result;
//    }

    public static int checkOtherInStorageNumber(Context context) {
        int result = -1;
        List<InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean> list = getInStorageOtherBean(context).getMaterielList();
        for (int i = 0; i < list.size(); i++) {
            InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean otherInStorageItem = list.get(i);
            if (TextUtils.isEmpty(otherInStorageItem.getInStorageNumber())) {
                result = i + 1;
                return result;
            }
        }
        return result;
    }

    public static int hasReceiveBatchInfo(List<InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean.BatchBean> list) {
        int result = NO_BATCH;
        if (list == null || list.isEmpty()) {
            return result;
        } else {
            result = BATCH_NO_MESSAGE;
            for (int i = 0; i < list.size(); i++) {
                InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean.BatchBean batchBean = list.get(i);
                String text = batchBean.getText();
                String value = batchBean.getValue();
                if (REQUIRED_TRUE.equals(batchBean.getRequired())) {
                    result = BATCH_NO_MESSAGE_BUT_REQUIRED;
                }
                if (!TextUtils.isEmpty(text) || !TextUtils.isEmpty(value)) {
                    result = BATCH_HAS_MESSAGE;
                    break;
                }
            }
        }
        return result;
    }

    //免检入库是否有批次特性
    public static int hasFreeBatchInfo(List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean.BatchBean> list) {
        int result = NO_BATCH;
        if (list == null || list.isEmpty()) {
            return result;
        } else {
            result = BATCH_NO_MESSAGE;
            for (int i = 0; i < list.size(); i++) {
                InStorageFreeOverviewBean.DataBean.FreeInStorageListBean.BatchBean batchBean = list.get(i);
                String text = batchBean.getText();
                String value = batchBean.getValue();
                if (REQUIRED_TRUE.equals(batchBean.getRequired())) {
                    result = BATCH_NO_MESSAGE_BUT_REQUIRED;
                }
                if (!TextUtils.isEmpty(text) || !TextUtils.isEmpty(value)) {
                    result = BATCH_HAS_MESSAGE;
                    break;
                }
            }
        }
        return result;
    }

    //招采入库是否有批次特性
    public static int hasTenderBatchInfo(List<InStorageTenderOverviewBean.DataBean.FreeInStorageListBean.BatchBean> list) {
        int result = NO_BATCH;
        if (list == null || list.isEmpty()) {
            return result;
        } else {
            result = BATCH_NO_MESSAGE;
            for (int i = 0; i < list.size(); i++) {
                InStorageTenderOverviewBean.DataBean.FreeInStorageListBean.BatchBean batchBean = list.get(i);
                String text = batchBean.getText();
                String value = batchBean.getValue();
                if (REQUIRED_TRUE.equals(batchBean.getRequired())) {
                    result = BATCH_NO_MESSAGE_BUT_REQUIRED;
                }
                if (!TextUtils.isEmpty(text) || !TextUtils.isEmpty(value)) {
                    result = BATCH_HAS_MESSAGE;
                    break;
                }
            }
        }
        return result;
    }

    public static int hasOtherBatchInfo(List<InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean.BatchBean> list) {
        int result = NO_BATCH;
        if (list == null || list.isEmpty()) {
            return result;
        } else {
            result = BATCH_NO_MESSAGE;
            for (int i = 0; i < list.size(); i++) {
                InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean.BatchBean batchBean = list.get(i);
                String text = batchBean.getText();
                String value = batchBean.getValue();
                if (REQUIRED_TRUE.equals(batchBean.getRequired())) {
                    result = BATCH_NO_MESSAGE_BUT_REQUIRED;
                }
                if (!TextUtils.isEmpty(text) || !TextUtils.isEmpty(value)) {
                    result = BATCH_HAS_MESSAGE;
                    break;
                }
            }
        }
        return result;
    }

    //获取验收入库信息
    public static InStorageReceiveOverviewBean getInStorageReceiveOverviewBean(Context context) {
        String json = SPUtils.getReceiveInStorageInformation(context);
        Gson gson = new Gson();
        return gson.fromJson(json, InStorageReceiveOverviewBean.class);
    }

    //获取免检入库信息
    public static InStorageFreeOverviewBean getInStorageFreeOverviewBean(Context context) {
        String json = SPUtils.getFreeInStorageInformation(context);
        Gson gson = new Gson();
        return gson.fromJson(json, InStorageFreeOverviewBean.class);
    }

    //获取招采入库信息
    public static InStorageTenderOverviewBean getInStorageTenderOverviewBean(Context context) {
        String json = SPUtils.getTenderInStorageInformation(context);
        Gson gson = new Gson();
        return gson.fromJson(json, InStorageTenderOverviewBean.class);
    }

    //保存免检入库信息
    public static void saveInStorageFreeOverviewBean(Context context, InStorageFreeOverviewBean bean) {
        Gson gson = new Gson();
        SPUtils.saveFreeInStorageInformation(context, gson.toJson(bean, InStorageFreeOverviewBean.class));
    }

    //保存其他入库信息
    public static void saveInStorageOtherBean(Context context, InStorageOtherBean bean) {
        Gson gson = new Gson();
        SPUtils.saveOtherInStorageInformation(context, gson.toJson(bean, InStorageOtherBean.class));
    }

    //保存招采入库信息
    public static void saveInStorageTenderOverviewBean(Context context, InStorageTenderOverviewBean bean) {
        Gson gson = new Gson();
        SPUtils.saveTenderInStorageInformation(context, gson.toJson(bean, InStorageTenderOverviewBean.class));
    }

    //获取其他入库信息
    public static InStorageOtherBean getInStorageOtherBean(Context context) {
        String json = SPUtils.getOtherInStorageInformation(context);
        if (TextUtils.isEmpty(json)) {
            return new InStorageOtherBean();
        } else {
            Gson gson = new Gson();
            return gson.fromJson(json, InStorageOtherBean.class);
        }
    }

    //过滤验收入库货品列表信息
    public static List<InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean> getReceiveInStorageList(Context context, String materiel) {
        List<InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean> receiveInStorageList = new ArrayList<>();
        List<InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean> allReceiveInStorageList = getInStorageReceiveOverviewBean(context).getData().getReceiveInStorageList();
        for (int i = 0; i < allReceiveInStorageList.size(); i++) {
            InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean item = allReceiveInStorageList.get(i);
            if (item.getMaterielCode().contains(materiel) || item.getMaterielDescription().contains(materiel)) {
                receiveInStorageList.add(item);
                continue;
            }
        }
        return receiveInStorageList;
    }

    //过滤免检入库货品列表信息
    public static List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean> getFreeInStorageList(Context context, String materiel) {
        List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean> freeInStorageList = new ArrayList<>();
        List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean> allFreeInStorageList = getInStorageFreeOverviewBean(context).getData().getFreeInStorageList();
        for (int i = 0; i < allFreeInStorageList.size(); i++) {
            InStorageFreeOverviewBean.DataBean.FreeInStorageListBean item = allFreeInStorageList.get(i);
            if (item.getMaterielCode().contains(materiel) || item.getMaterielDescription().contains(materiel)) {
                freeInStorageList.add(item);
                continue;
            }
        }
        return freeInStorageList;
    }

    //过滤招采入库货品列表信息
    public static List<InStorageTenderOverviewBean.DataBean.FreeInStorageListBean> getTenderInStorageList(Context context, String materiel) {
        List<InStorageTenderOverviewBean.DataBean.FreeInStorageListBean> tenderInStorageList = new ArrayList<>();
        List<InStorageTenderOverviewBean.DataBean.FreeInStorageListBean> allTenderInStorageList = getInStorageTenderOverviewBean(context).getData().getFreeInStorageList();
        for (int i = 0; i < allTenderInStorageList.size(); i++) {
            InStorageTenderOverviewBean.DataBean.FreeInStorageListBean item = allTenderInStorageList.get(i);
            if (item.getMaterielCode().contains(materiel) || item.getMaterielDescription().contains(materiel)) {
                tenderInStorageList.add(item);
                continue;
            }
        }
        return tenderInStorageList;
    }

    public static InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean getReceiveMaterielInformationBySerial(Context context, String serialNumber) {
        List<InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean> list = getInStorageReceiveOverviewBean(context).getData().getReceiveInStorageList();
        for (int i = 0; i < list.size(); i++) {
            InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean item = list.get(i);
            if (serialNumber.equals(item.getSerial())) {
                return item;
            }
        }
        return null;
    }

    //通过序号获取免检入库物料明细
    public static InStorageFreeOverviewBean.DataBean.FreeInStorageListBean getFreeMaterielInformationBySerial(Context context, String serialNumber) {
        List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean> list = getInStorageFreeOverviewBean(context).getData().getFreeInStorageList();
        for (int i = 0; i < list.size(); i++) {
            InStorageFreeOverviewBean.DataBean.FreeInStorageListBean item = list.get(i);
            if (serialNumber.equals(item.getSerial())) {
                return item;
            }
        }
        return null;
    }

    //通过序号获取招采入库物料明细
    public static InStorageTenderOverviewBean.DataBean.FreeInStorageListBean getTenderMaterielInformationBySerial(Context context, String serialNumber) {
        List<InStorageTenderOverviewBean.DataBean.FreeInStorageListBean> list = getInStorageTenderOverviewBean(context).getData().getFreeInStorageList();
        for (int i = 0; i < list.size(); i++) {
            InStorageTenderOverviewBean.DataBean.FreeInStorageListBean item = list.get(i);
            if (serialNumber.equals(item.getSerial())) {
                return item;
            }
        }
        return null;
    }

    public static InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean getOtherMaterielInformationByMaterielCode(Context context, String materielCode) {
        List<InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean> list = getInStorageOtherBean(context).getMaterielList();
        for (int i = 0; i < list.size(); i++) {
            InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean item = list.get(i);
            if (materielCode.equals(item.getMaterielCode())) {
                return item;
            }
        }
        return null;
    }

    public static List<InStorageReceiveOverviewBean.DataBean.InventoryAddressListBean> getReceiveInventoryAddressList(Context context) {
        List<InStorageReceiveOverviewBean.DataBean.InventoryAddressListBean> result = getInStorageReceiveOverviewBean(context).getData().getInventoryAddressList();
        return result;
    }

    //获取免检入库库存地点列表
    public static List<InStorageFreeOverviewBean.DataBean.InventoryAddressListBean> getFreeInventoryAddressList(Context context) {
        List<InStorageFreeOverviewBean.DataBean.InventoryAddressListBean> result = getInStorageFreeOverviewBean(context).getData().getInventoryAddressList();
        return result;
    }

    //获取招采入库库存地点列表
    public static List<InStorageTenderOverviewBean.DataBean.InventoryAddressListBean> getTenderInventoryAddressList(Context context) {
        List<InStorageTenderOverviewBean.DataBean.InventoryAddressListBean> result = getInStorageTenderOverviewBean(context).getData().getInventoryAddressList();
        return result;
    }

    public static void createEditText(Context context, ViewGroup viewGroup, String name, boolean required, String text, String value, int id) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.view_in_storage_edittext, null);
        view.setId(id);
        TextView nameTextView = (TextView) view.findViewById(R.id.name);
        EditText textEditText = (EditText) view.findViewById(R.id.text);
        if (required) {
            String nameStr = name + "*";
            SpannableStringBuilder builder = new SpannableStringBuilder(nameStr);
            ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);
            builder.setSpan(redSpan, nameStr.length() - 1, nameStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            nameTextView.setText(builder);
        } else {
            nameTextView.setText(name);
        }
        textEditText.setText(text);
        viewGroup.addView(view);
    }

    public static void createDatePicker(BaseActivity activity, ViewGroup viewGroup, String name, boolean required, String text, String value, int id) {
        LayoutInflater inflater = LayoutInflater.from(activity);
        View view = inflater.inflate(R.layout.view_in_storage_textview, null);
        view.setId(id);
        TextView nameTextView = (TextView) view.findViewById(R.id.name);
        TextView textTextView = (TextView) view.findViewById(R.id.text);
        if (required) {
            String nameStr = name + "*";
            SpannableStringBuilder builder = new SpannableStringBuilder(nameStr);
            ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);
            builder.setSpan(redSpan, nameStr.length() - 1, nameStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            nameTextView.setText(builder);
        } else {
            nameTextView.setText(name);
        }
        textTextView.setText(text);
        textTextView.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                getTimePickerDialog(activity, textTextView.getText().toString(), (TimePickerDialog timePickerView, long millseconds) -> {
                    textTextView.setText(Utils.getStringDateFromTimeStamp(UtilsConstant.YYYY_MM_DD, millseconds));
                }).show(activity.getSupportFragmentManager(), "datePicker");
            }
        });
        viewGroup.addView(view);
    }

    private static TimePickerDialog getTimePickerDialog(Context context, String time, OnDateSetListener onDateSetListener) {
        TimePickerDialog.Builder yearMonthDay = new TimePickerDialog.Builder()
                .setType(Type.YEAR_MONTH_DAY)
                .setThemeColor(ContextCompat.getColor(context, R.color.include_header_background))
                .setCallBack(onDateSetListener)
                .setTitleStringId(context.getResources().getString(R.string.common_select_date));
        if (time == null || "".equals(time)) {
            yearMonthDay.setCurrentMillseconds(System.currentTimeMillis());
        } else {
            yearMonthDay.setCurrentMillseconds(Utils.getTimeStampFromString(UtilsConstant.YYYY_MM_DD, time));
        }
        return yearMonthDay.build();
    }

    private static String getReceiveTextByValue(String value, List<InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean.BatchBean.SelectBean> selectList) {
        for (int i = 0; i < selectList.size(); i++) {
            InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean.BatchBean.SelectBean selectBean = selectList.get(i);
            if (selectBean.getValue().equals(value)) {
                return selectBean.getText();
            }
        }
        return "";
    }

    private static String getFreeTextByValue(String value, List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean.BatchBean.SelectBean> selectList) {
        for (int i = 0; i < selectList.size(); i++) {
            InStorageFreeOverviewBean.DataBean.FreeInStorageListBean.BatchBean.SelectBean selectBean = selectList.get(i);
            if (selectBean.getValue().equals(value)) {
                return selectBean.getText();
            }
        }
        return "";
    }

    private static String getTenderTextByValue(String value, List<InStorageTenderOverviewBean.DataBean.FreeInStorageListBean.BatchBean.SelectBean> selectList) {
        for (int i = 0; i < selectList.size(); i++) {
            InStorageTenderOverviewBean.DataBean.FreeInStorageListBean.BatchBean.SelectBean selectBean = selectList.get(i);
            if (selectBean.getValue().equals(value)) {
                return selectBean.getText();
            }
        }
        return "";
    }

    private static String getOtherTextByValue(String value, List<InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean.BatchBean.SelectBean> selectList) {
        for (int i = 0; i < selectList.size(); i++) {
            InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean.BatchBean.SelectBean selectBean = selectList.get(i);
            if (selectBean.getValue().equals(value)) {
                return selectBean.getText();
            }
        }
        return "";
    }

    public static void createReceiveSelect(Context context, ViewGroup viewGroup, String name, boolean required, String text, String value, List<InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean.BatchBean.SelectBean> selectList, int id) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.view_in_storage_textview, null);
        view.setId(id);
        TextView nameTextView = (TextView) view.findViewById(R.id.name);
        TextView textTextView = (TextView) view.findViewById(R.id.text);
        TextView valueTextView = (TextView) view.findViewById(R.id.value);
        if (required) {
            String nameStr = name + "*";
            SpannableStringBuilder builder = new SpannableStringBuilder(nameStr);
            ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);
            builder.setSpan(redSpan, nameStr.length() - 1, nameStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            nameTextView.setText(builder);
        } else {
            nameTextView.setText(name);
        }
        textTextView.setText(getReceiveTextByValue(value, selectList));
        valueTextView.setText(value);
        textTextView.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                DialogUtils.getReceiveSelectDialog(context, selectList, new DialogUtils.SelectListener() {
                    @Override
                    public void onSelect(Dialog dialog, String text, String value) {
                        textTextView.setText(text);
                        valueTextView.setText(value);
                    }
                }).show();
            }
        });
        viewGroup.addView(view);
    }

    //创建免检入库下拉选择框
    public static void createFreeSelect(Context context, ViewGroup viewGroup, String name, boolean required, String text, String value, List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean.BatchBean.SelectBean> selectList, int id) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.view_in_storage_textview, null);
        view.setId(id);
        TextView nameTextView = (TextView) view.findViewById(R.id.name);
        TextView textTextView = (TextView) view.findViewById(R.id.text);
        TextView valueTextView = (TextView) view.findViewById(R.id.value);
        if (required) {
            String nameStr = name + "*";
            SpannableStringBuilder builder = new SpannableStringBuilder(nameStr);
            ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);
            builder.setSpan(redSpan, nameStr.length() - 1, nameStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            nameTextView.setText(builder);
        } else {
            nameTextView.setText(name);
        }
        textTextView.setText(getFreeTextByValue(value, selectList));
        valueTextView.setText(value);
        textTextView.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                DialogUtils.getFreeSelectDialog(context, selectList, new DialogUtils.SelectListener() {
                    @Override
                    public void onSelect(Dialog dialog, String text, String value) {
                        textTextView.setText(text);
                        valueTextView.setText(value);
                    }
                }).show();
            }
        });
        viewGroup.addView(view);
    }

    //创建招采入库下拉选择框
    public static void createTenderSelect(Context context, ViewGroup viewGroup, String name, boolean required, String text, String value, List<InStorageTenderOverviewBean.DataBean.FreeInStorageListBean.BatchBean.SelectBean> selectList, int id) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.view_in_storage_textview, null);
        view.setId(id);
        TextView nameTextView = (TextView) view.findViewById(R.id.name);
        TextView textTextView = (TextView) view.findViewById(R.id.text);
        TextView valueTextView = (TextView) view.findViewById(R.id.value);
        if (required) {
            String nameStr = name + "*";
            SpannableStringBuilder builder = new SpannableStringBuilder(nameStr);
            ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);
            builder.setSpan(redSpan, nameStr.length() - 1, nameStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            nameTextView.setText(builder);
        } else {
            nameTextView.setText(name);
        }
        textTextView.setText(getTenderTextByValue(value, selectList));
        valueTextView.setText(value);
        textTextView.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                DialogUtils.getTenderSelectDialog(context, selectList, new DialogUtils.SelectListener() {
                    @Override
                    public void onSelect(Dialog dialog, String text, String value) {
                        textTextView.setText(text);
                        valueTextView.setText(value);
                    }
                }).show();
            }
        });
        viewGroup.addView(view);
    }

    public static void createOtherSelect(Context context, ViewGroup viewGroup, String name, boolean required, String text, String value, List<InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean.BatchBean.SelectBean> selectList, int id) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.view_in_storage_textview, null);
        view.setId(id);
        TextView nameTextView = (TextView) view.findViewById(R.id.name);
        TextView textTextView = (TextView) view.findViewById(R.id.text);
        TextView valueTextView = (TextView) view.findViewById(R.id.value);
        if (required) {
            String nameStr = name + "*";
            SpannableStringBuilder builder = new SpannableStringBuilder(nameStr);
            ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);
            builder.setSpan(redSpan, nameStr.length() - 1, nameStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            nameTextView.setText(builder);
        } else {
            nameTextView.setText(name);
        }
        textTextView.setText(getOtherTextByValue(value, selectList));
        valueTextView.setText(value);
        textTextView.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                DialogUtils.getOtherSelectDialog(context, selectList, new DialogUtils.SelectListener() {
                    @Override
                    public void onSelect(Dialog dialog, String text, String value) {
                        textTextView.setText(text);
                        valueTextView.setText(value);
                    }
                }).show();
            }
        });
        viewGroup.addView(view);
    }

    public static void updateReceiveInStorageItem(Context context, InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean materielItem) {
        InStorageReceiveOverviewBean bean = getInStorageReceiveOverviewBean(context);
        List<InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean> receiveInstoragelist = bean.getData().getReceiveInStorageList();
        for (int i = 0; i < receiveInstoragelist.size(); i++) {
            InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean receiveInstorageItem = receiveInstoragelist.get(i);
            if (materielItem.getSerial().equals(receiveInstorageItem.getSerial())) {
                receiveInstoragelist.remove(receiveInstorageItem);
                break;
            }
        }
        receiveInstoragelist.add(0, materielItem);
        bean.getData().setReceiveInStorageList(receiveInstoragelist);
        Gson gson = new Gson();
        String json = gson.toJson(bean, InStorageReceiveOverviewBean.class);
        SPUtils.saveReceiveInStorageInformation(context, json);
    }

    //更新免检入库行项目
    public static void updateFreeInStorageItem(Context context, InStorageFreeOverviewBean.DataBean.FreeInStorageListBean materielItem) {
        InStorageFreeOverviewBean bean = getInStorageFreeOverviewBean(context);
        List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean> freeInstoragelist = bean.getData().getFreeInStorageList();
        for (int i = 0; i < freeInstoragelist.size(); i++) {
            InStorageFreeOverviewBean.DataBean.FreeInStorageListBean freeInstorageItem = freeInstoragelist.get(i);
            if (materielItem.getSerial().equals(freeInstorageItem.getSerial())) {
                freeInstoragelist.remove(freeInstorageItem);
                break;
            }
        }
        freeInstoragelist.add(0, materielItem);
        bean.getData().setFreeInStorageList(freeInstoragelist);
        Gson gson = new Gson();
        String json = gson.toJson(bean, InStorageFreeOverviewBean.class);
        SPUtils.saveFreeInStorageInformation(context, json);
    }

    //更新招采入库行项目
    public static void updateTenderInStorageItem(Context context, InStorageTenderOverviewBean.DataBean.FreeInStorageListBean materielItem) {
        InStorageTenderOverviewBean bean = getInStorageTenderOverviewBean(context);
        List<InStorageTenderOverviewBean.DataBean.FreeInStorageListBean> tenderInstoragelist = bean.getData().getFreeInStorageList();
        for (int i = 0; i < tenderInstoragelist.size(); i++) {
            InStorageTenderOverviewBean.DataBean.FreeInStorageListBean tenderInstorageItem = tenderInstoragelist.get(i);
            if (materielItem.getSerial().equals(tenderInstorageItem.getSerial())) {
                tenderInstoragelist.remove(tenderInstorageItem);
                break;
            }
        }
        tenderInstoragelist.add(0, materielItem);
        bean.getData().setFreeInStorageList(tenderInstoragelist);
        Gson gson = new Gson();
        String json = gson.toJson(bean, InStorageTenderOverviewBean.class);
        SPUtils.saveTenderInStorageInformation(context, json);
    }

    public static void updateOtherInStorageItem(Context context, InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean materielItem) {
        InStorageOtherBean bean = getInStorageOtherBean(context);
        List<InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean> otherInstoragelist = bean.getMaterielList();
        for (int i = 0; i < otherInstoragelist.size(); i++) {
            InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean otherInstorageItem = otherInstoragelist.get(i);
            if (materielItem.getMaterielCode().equals(otherInstorageItem.getMaterielCode())) {
                otherInstoragelist.remove(otherInstorageItem);
                break;
            }
        }
        otherInstoragelist.add(0, materielItem);
        bean.setMaterielList(otherInstoragelist);
        Gson gson = new Gson();
        String json = gson.toJson(bean, InStorageOtherBean.class);
        SPUtils.saveOtherInStorageInformation(context, json);
    }

    public static void updateFreeReason(Context context, String value) {
        InStorageFreeOverviewBean bean = getInStorageFreeOverviewBean(context);
        bean.getData().setReaseonValue(value);
        Gson gson = new Gson();
        String json = gson.toJson(bean, InStorageFreeOverviewBean.class);
        SPUtils.saveFreeInStorageInformation(context, json);
    }

    public static String checkFreeReason(Context context) {
        InStorageFreeOverviewBean bean = getInStorageFreeOverviewBean(context);
        return bean.getData().getReaseonValue();
    }

//    public static <T> T fromJson(String json, Class<T> className) {
//        String data = json.replace("\\", "");
//        Gson gson = new Gson();
//        T result = gson.fromJson(data, className);
//        return result;
//    }
//
//    public static <T> String toJson(T jsonBean, Class<T> className) {
//        Gson gson = new Gson();
//        String result = gson.toJson(jsonBean, className);
//        return result.replace("\"", "\\\"");
//    }

    //删除验收入库验收人
    public static void deleteReceiveOperator(Context context, String id) {
        InStorageReceiveOverviewBean bean = getInStorageReceiveOverviewBean(context);
        List<InStorageReceiveOverviewBean.DataBean.OperatorListBean> operatorList = bean.getData().getOperatorList();
        for (int i = 0; i < operatorList.size(); i++) {
            InStorageReceiveOverviewBean.DataBean.OperatorListBean operatorItem = operatorList.get(i);
            if (operatorItem.getId().equals(id)) {
                operatorList.remove(operatorItem);
                break;
            }
        }
        bean.getData().setOperatorList(operatorList);
        Gson gson = new Gson();
        String json = gson.toJson(bean, InStorageReceiveOverviewBean.class);
        SPUtils.saveReceiveInStorageInformation(context, json);
    }

    //删除免检入库验收人
    public static void deleteFreeOperator(Context context, String id) {
        InStorageFreeOverviewBean bean = getInStorageFreeOverviewBean(context);
        List<InStorageFreeOverviewBean.DataBean.OperatorListBean> operatorList = bean.getData().getOperatorList();
        for (int i = 0; i < operatorList.size(); i++) {
            InStorageFreeOverviewBean.DataBean.OperatorListBean operatorItem = operatorList.get(i);
            if (operatorItem.getId().equals(id)) {
                operatorList.remove(operatorItem);
                break;
            }
        }
        bean.getData().setOperatorList(operatorList);
        Gson gson = new Gson();
        String json = gson.toJson(bean, InStorageFreeOverviewBean.class);
        SPUtils.saveFreeInStorageInformation(context, json);
    }

    //删除其他入库验收人
    public static void deleteOtherOperator(Context context, String id) {
        InStorageOtherBean bean = getInStorageOtherBean(context);
        List<InStorageOtherBean.OperatorListBean> operatorList = bean.getOperatorList();
        for (int i = 0; i < operatorList.size(); i++) {
            InStorageOtherBean.OperatorListBean operatorItem = operatorList.get(i);
            if (operatorItem.getId().equals(id)) {
                operatorList.remove(operatorItem);
                break;
            }
        }
        bean.setOperatorList(operatorList);
        Gson gson = new Gson();
        String json = gson.toJson(bean, InStorageOtherBean.class);
        SPUtils.saveOtherInStorageInformation(context, json);
    }

    //删除其他入库物料信息
    public static void deleteOtherMateriel(Context context, String materielCode) {
        InStorageOtherBean bean = getInStorageOtherBean(context);
        List<InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean> list = bean.getMaterielList();
        for (int i = 0; i < list.size(); i++) {
            InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean materielItem = list.get(i);
            if (materielItem.getMaterielCode().equals(materielCode)) {
                list.remove(materielItem);
                break;
            }
        }
        bean.setMaterielList(list);
        Gson gson = new Gson();
        String json = gson.toJson(bean, InStorageOtherBean.class);
        SPUtils.saveOtherInStorageInformation(context, json);
    }

    //添加验收入库验收人
    public static void addReceiveOperator(Context context, InStorageReceiveOverviewBean.DataBean.OperatorListBean receiveItem) {
        InStorageReceiveOverviewBean bean = getInStorageReceiveOverviewBean(context);
        List<InStorageReceiveOverviewBean.DataBean.OperatorListBean> receiverList = bean.getData().getOperatorList();
        receiverList.add(0, receiveItem);
        bean.getData().setOperatorList(receiverList);
        Gson gson = new Gson();
        String json = gson.toJson(bean, InStorageReceiveOverviewBean.class);
        SPUtils.saveReceiveInStorageInformation(context, json);
    }

    //添加免检入库验收人
    public static void addFreeOperator(Context context, InStorageFreeOverviewBean.DataBean.OperatorListBean receiveItem) {
        InStorageFreeOverviewBean bean = getInStorageFreeOverviewBean(context);
        List<InStorageFreeOverviewBean.DataBean.OperatorListBean> receiverList = bean.getData().getOperatorList();
        receiverList.add(0, receiveItem);
        bean.getData().setOperatorList(receiverList);
        Gson gson = new Gson();
        String json = gson.toJson(bean, InStorageFreeOverviewBean.class);
        SPUtils.saveFreeInStorageInformation(context, json);
    }

    //添加招采入库验收人
    public static void addTenderOperator(Context context, InStorageTenderOverviewBean.DataBean.OperatorListBean receiveItem) {
        InStorageTenderOverviewBean bean = getInStorageTenderOverviewBean(context);
        List<InStorageTenderOverviewBean.DataBean.OperatorListBean> receiverList = bean.getData().getOperatorList();
        receiverList.add(0, receiveItem);
        bean.getData().setOperatorList(receiverList);
        Gson gson = new Gson();
        String json = gson.toJson(bean, InStorageTenderOverviewBean.class);
        SPUtils.saveTenderInStorageInformation(context, json);
    }

    //添加其他入库验收人
    public static void addOtherOperator(Context context, InStorageOtherBean.OperatorListBean receiveItem) {
        InStorageOtherBean bean = getInStorageOtherBean(context);
        List<InStorageOtherBean.OperatorListBean> receiverList = bean.getOperatorList();
        if (receiverList == null) {
            receiverList = new ArrayList<>();
        }
        receiverList.add(0, receiveItem);
        bean.setOperatorList(receiverList);
        Gson gson = new Gson();
        String json = gson.toJson(bean, InStorageOtherBean.class);
        SPUtils.saveOtherInStorageInformation(context, json);
    }

    //是否有验收入库操作人员
    public static boolean hasReceiveOperator(Context context) {
        List<InStorageReceiveOverviewBean.DataBean.OperatorListBean> operatorList = getInStorageReceiveOverviewBean(context).getData().getOperatorList();
        if (operatorList != null && !operatorList.isEmpty()) {
            return true;
        }
        return false;
    }

    //是否有免检入库操作人员
    public static boolean hasFreeOperator(Context context) {
        List<InStorageFreeOverviewBean.DataBean.OperatorListBean> operatorList = getInStorageFreeOverviewBean(context).getData().getOperatorList();
        if (operatorList != null && !operatorList.isEmpty()) {
            return true;
        }
        return false;
    }

    //是否有招采入库操作人员
    public static boolean hasTenderOperator(Context context) {
        List<InStorageTenderOverviewBean.DataBean.OperatorListBean> operatorList = getInStorageTenderOverviewBean(context).getData().getOperatorList();
        if (operatorList != null && !operatorList.isEmpty()) {
            return true;
        }
        return false;
    }

    //是否有其他入库操作人员
    public static boolean hasOtherOperator(Context context) {
        List<InStorageOtherBean.OperatorListBean> operatorList = getInStorageOtherBean(context).getOperatorList();
        if (operatorList != null && !operatorList.isEmpty()) {
            return true;
        }
        return false;
    }

    //拼验收入库对象
    public static InStorageReceiveConfirmRequestBean getInStorageReceiveConfirmRequestBean(Context context, String voucherDate, String postDate, boolean isFocus) {
        InStorageReceiveConfirmRequestBean result = new InStorageReceiveConfirmRequestBean();
        InStorageReceiveOverviewBean bean = getInStorageReceiveOverviewBean(context);
        result.setInStorageNumber(bean.getData().getInStorageNumber());
        result.setVoucherDate(voucherDate);
        result.setPostDate(postDate);
        result.setIsFocus(isFocus ? IS_FOCUS_TRUE : IS_FOCUS_FALSE);
        //操作人
        List<InStorageReceiveConfirmRequestBean.OperatorListBean> resultOperatorList = new ArrayList<>();
        List<InStorageReceiveOverviewBean.DataBean.OperatorListBean> operatorList = bean.getData().getOperatorList();
        for (int i = 0; i < operatorList.size(); i++) {
            InStorageReceiveConfirmRequestBean.OperatorListBean operator = new InStorageReceiveConfirmRequestBean.OperatorListBean();
            operator.setRoleCode(operatorList.get(i).getRoleCode());
            operator.setId(operatorList.get(i).getId());
            resultOperatorList.add(operator);
        }
        result.setOperatorList(resultOperatorList);
        //物料
        List<InStorageReceiveConfirmRequestBean.MaterielListBean> resultMaterielList = new ArrayList<>();
        List<InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean> receiveInStorageList = bean.getData().getReceiveInStorageList();
        for (int i = 0; i < receiveInStorageList.size(); i++) {
            InStorageReceiveConfirmRequestBean.MaterielListBean resultMateriel = new InStorageReceiveConfirmRequestBean.MaterielListBean();
            InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean receiveInStorage = receiveInStorageList.get(i);
            resultMateriel.setSerial(receiveInStorage.getSerial());
            resultMateriel.setInventoryAddressCode(receiveInStorage.getInventoryAddressCode());
            resultMateriel.setFactoryCode(receiveInStorage.getFactoryCode());
            resultMateriel.setInStorageNumber(TextUtils.isEmpty(receiveInStorage.getRealInStorageNumber()) ? receiveInStorage.getInStorageNumber() : receiveInStorage.getRealInStorageNumber());
            resultMateriel.setBatchId(receiveInStorage.getBatchId());
            List<InStorageReceiveConfirmRequestBean.MaterielListBean.BatchListBean> resultBatchList = new ArrayList<>();
            List<InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean.BatchBean> batchList = receiveInStorage.getBatch();
            for (int j = 0; j < batchList.size(); j++) {
                InStorageReceiveConfirmRequestBean.MaterielListBean.BatchListBean resultBatch = new InStorageReceiveConfirmRequestBean.MaterielListBean.BatchListBean();
                InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean.BatchBean batch = batchList.get(j);
                resultBatch.setId(batch.getId());
                resultBatch.setType(batch.getType());
                resultBatch.setText(batch.getText());
                resultBatch.setValue(batch.getValue());
                resultBatchList.add(resultBatch);
            }
            resultMateriel.setBatchList(resultBatchList);
            resultMaterielList.add(resultMateriel);
        }
        result.setMaterielList(resultMaterielList);
        return result;
    }

    //拼免检入库对象
    public static InStorageFreeConfirmRequestBean getInStorageFreeConfirmRequestBean(Context context, String voucherDate, String postDate, boolean isFocus) {
        InStorageFreeConfirmRequestBean result = new InStorageFreeConfirmRequestBean();
        InStorageFreeOverviewBean bean = getInStorageFreeOverviewBean(context);
        result.setInStorageNumber(bean.getData().getInStorageNumber());
        result.setReaseon(bean.getData().getReaseonValue());
        result.setPurchase(bean.getData().getPurchase());
        result.setVoucherDate(voucherDate);
        result.setPostDate(postDate);
        result.setIsFocus(isFocus ? IS_FOCUS_TRUE : IS_FOCUS_FALSE);
        //操作人
        List<InStorageFreeConfirmRequestBean.OperatorListBean> resultOperatorList = new ArrayList<>();
        List<InStorageFreeOverviewBean.DataBean.OperatorListBean> operatorList = bean.getData().getOperatorList();
        for (int i = 0; i < operatorList.size(); i++) {
            InStorageFreeConfirmRequestBean.OperatorListBean operator = new InStorageFreeConfirmRequestBean.OperatorListBean();
            operator.setRoleCode(operatorList.get(i).getRoleCode());
            operator.setId(operatorList.get(i).getId());
            resultOperatorList.add(operator);
        }
        result.setOperatorList(resultOperatorList);
        //物料
        List<InStorageFreeConfirmRequestBean.MaterielListBean> resultMaterielList = new ArrayList<>();
        List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean> freeInStorageList = bean.getData().getFreeInStorageList();
        for (int i = 0; i < freeInStorageList.size(); i++) {
            InStorageFreeConfirmRequestBean.MaterielListBean resultMateriel = new InStorageFreeConfirmRequestBean.MaterielListBean();
            InStorageFreeOverviewBean.DataBean.FreeInStorageListBean freeInStorage = freeInStorageList.get(i);
            resultMateriel.setSerial(freeInStorage.getSerial());
            resultMateriel.setInventoryAddressCode(freeInStorage.getInventoryAddressCode());
            resultMateriel.setFactoryCode(freeInStorage.getFactoryCode());
            resultMateriel.setInStorageNumber(freeInStorage.getInStorageNumber());
            List<InStorageFreeConfirmRequestBean.MaterielListBean.BatchListBean> resultBatchList = new ArrayList<>();
            List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean.BatchBean> batchList = freeInStorage.getBatch();
            for (int j = 0; j < batchList.size(); j++) {
                InStorageFreeConfirmRequestBean.MaterielListBean.BatchListBean resultBatch = new InStorageFreeConfirmRequestBean.MaterielListBean.BatchListBean();
                InStorageFreeOverviewBean.DataBean.FreeInStorageListBean.BatchBean batch = batchList.get(j);
                resultBatch.setId(batch.getId());
                resultBatch.setType(batch.getType());
                resultBatch.setText(batch.getText());
                resultBatch.setValue(batch.getValue());
                resultBatchList.add(resultBatch);
            }
            resultMateriel.setBatchList(resultBatchList);
            if (!"".equals(resultMateriel.getInStorageNumber())) {
                resultMaterielList.add(resultMateriel);
            }
        }
        result.setMaterielList(resultMaterielList);
        return result;
    }

    //拼招采入库对象
    public static InStorageTenderConfirmRequestBean getInStorageTenderConfirmRequestBean(Context context, String voucherDate, String postDate, boolean isFocus) {
        InStorageTenderConfirmRequestBean result = new InStorageTenderConfirmRequestBean();
        InStorageTenderOverviewBean bean = getInStorageTenderOverviewBean(context);
        result.setInStorageNumber(bean.getData().getInStorageNumber());
        result.setReaseon(bean.getData().getReaseonValue());
        result.setPurchase(bean.getData().getPurchase());
        result.setVoucherDate(voucherDate);
        result.setPostDate(postDate);
        result.setIsFocus(isFocus ? IS_FOCUS_TRUE : IS_FOCUS_FALSE);
        //操作人
        List<InStorageTenderConfirmRequestBean.OperatorListBean> resultOperatorList = new ArrayList<>();
        List<InStorageTenderOverviewBean.DataBean.OperatorListBean> operatorList = bean.getData().getOperatorList();
        for (int i = 0; i < operatorList.size(); i++) {
            InStorageTenderConfirmRequestBean.OperatorListBean operator = new InStorageTenderConfirmRequestBean.OperatorListBean();
            operator.setRoleCode(operatorList.get(i).getRoleCode());
            operator.setId(operatorList.get(i).getId());
            resultOperatorList.add(operator);
        }
        result.setOperatorList(resultOperatorList);
        //物料
        List<InStorageTenderConfirmRequestBean.MaterielListBean> resultMaterielList = new ArrayList<>();
        List<InStorageTenderOverviewBean.DataBean.FreeInStorageListBean> tenderInStorageList = bean.getData().getFreeInStorageList();
        for (int i = 0; i < tenderInStorageList.size(); i++) {
            InStorageTenderConfirmRequestBean.MaterielListBean resultMateriel = new InStorageTenderConfirmRequestBean.MaterielListBean();
            InStorageTenderOverviewBean.DataBean.FreeInStorageListBean tenderInStorage = tenderInStorageList.get(i);
            resultMateriel.setSerial(tenderInStorage.getSerial());
            resultMateriel.setInventoryAddressCode(tenderInStorage.getInventoryAddressCode());
            resultMateriel.setFactoryCode(tenderInStorage.getFactoryCode());
            resultMateriel.setInStorageNumber(tenderInStorage.getInStorageNumber());
            List<InStorageTenderConfirmRequestBean.MaterielListBean.BatchListBean> resultBatchList = new ArrayList<>();
            List<InStorageTenderOverviewBean.DataBean.FreeInStorageListBean.BatchBean> batchList = tenderInStorage.getBatch();
            for (int j = 0; j < batchList.size(); j++) {
                InStorageTenderConfirmRequestBean.MaterielListBean.BatchListBean resultBatch = new InStorageTenderConfirmRequestBean.MaterielListBean.BatchListBean();
                InStorageTenderOverviewBean.DataBean.FreeInStorageListBean.BatchBean batch = batchList.get(j);
                resultBatch.setId(batch.getId());
                resultBatch.setType(batch.getType());
                resultBatch.setText(batch.getText());
                resultBatch.setValue(batch.getValue());
                resultBatchList.add(resultBatch);
            }
            resultMateriel.setBatchList(resultBatchList);
            if (!"".equals(resultMateriel.getInStorageNumber())) {
                resultMaterielList.add(resultMateriel);
            }
        }
        result.setMaterielList(resultMaterielList);
        return result;
    }

    //拼免检入库对象
    public static InStorageOtherConfirmRequestBean getInStorageOtherConfirmRequestBean(Context context, String voucherDate, String postDate, boolean isFocus) {
        InStorageOtherConfirmRequestBean result = new InStorageOtherConfirmRequestBean();
        InStorageOtherBean bean = getInStorageOtherBean(context);
        result.setInStorageNumber(bean.getInStorageNumber());
        result.setVoucherDate(voucherDate);
        result.setPostDate(postDate);
        result.setFactoryCode(bean.getFactoryCode());
        result.setFactoryValue(bean.getFactoryValue());
        result.setInventoryAddressCode(bean.getInventoryAddressCode());
        result.setInventoryAddressValue(bean.getInventoryAddressValue());
        result.setMoveType(bean.getMoveType());
        result.setSpecialInventory(bean.getSpecialInventory());
        result.setMoveDescription(bean.getMoveDescription());
        result.setInStorageReasonCode(bean.getInStorageReasonCode());
        result.setInStorageReasonValue(bean.getInStorageReasonValue());
        result.setSupplierCode(bean.getSupplierCode());
        result.setSupplierValue(bean.getSupplierDescription());
        result.setSpecialInventoryCode(bean.getSpecialInventoryCode());
        result.setSpecialInventoryDescription(bean.getSpecialInventoryDescription());
        result.setIsFocus(isFocus ? IS_FOCUS_TRUE : IS_FOCUS_FALSE);
        //操作人
        List<InStorageOtherConfirmRequestBean.OperatorListBean> resultOperatorList = new ArrayList<>();
        List<InStorageOtherBean.OperatorListBean> operatorList = bean.getOperatorList();
        for (int i = 0; i < operatorList.size(); i++) {
            InStorageOtherConfirmRequestBean.OperatorListBean operator = new InStorageOtherConfirmRequestBean.OperatorListBean();
            operator.setRoleCode(operatorList.get(i).getRoleCode());
            operator.setId(operatorList.get(i).getId());
            resultOperatorList.add(operator);
        }
        result.setOperatorList(resultOperatorList);
        //物料
        List<InStorageOtherConfirmRequestBean.MaterielListBean> resultMaterielList = new ArrayList<>();
        List<InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean> otherInstorageList = bean.getMaterielList();
        for (int i = 0; i < otherInstorageList.size(); i++) {
            InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean otherInStorage = otherInstorageList.get(i);
            InStorageOtherConfirmRequestBean.MaterielListBean resultMateriel = new InStorageOtherConfirmRequestBean.MaterielListBean();
            resultMateriel.setMaterielCode(otherInStorage.getMaterielCode());
            resultMateriel.setMaterielDescription(otherInStorage.getMaterielDescription());
            resultMateriel.setInStorageNumber(otherInStorage.getInStorageNumber());
            resultMateriel.setUnit(otherInStorage.getUnit());
            resultMateriel.setUnitCode(otherInStorage.getUnitCode());
            resultMateriel.setBatchId(otherInStorage.getBatchId());

            List<InStorageOtherConfirmRequestBean.MaterielListBean.BatchListBean> resultBatchList = new ArrayList<>();
            List<InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean.BatchBean> batchList = otherInStorage.getBatch();
            for (int j = 0; j < batchList.size(); j++) {
                InStorageOtherConfirmRequestBean.MaterielListBean.BatchListBean resultBatch = new InStorageOtherConfirmRequestBean.MaterielListBean.BatchListBean();
                InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean.BatchBean batch = batchList.get(j);
                resultBatch.setId(batch.getId());
                resultBatch.setType(batch.getType());
                resultBatch.setText(batch.getText());
                resultBatch.setValue(batch.getValue());
                resultBatchList.add(resultBatch);
            }
            resultMateriel.setBatchList(resultBatchList);
            if (!"".equals(resultMateriel.getInStorageNumber())) {
                resultMaterielList.add(resultMateriel);
            }
        }
        result.setMaterielList(resultMaterielList);
        return result;
    }

    public static void updateFreeInStorageNumber(Context context, String inStorageNumber) {
        InStorageFreeOverviewBean bean = getInStorageFreeOverviewBean(context);
        bean.getData().setInStorageNumber(inStorageNumber);
        saveInStorageFreeOverviewBean(context, bean);
    }

    public static void updateOtherInStorageNumber(Context context, String inStorageNumber) {
        InStorageOtherBean bean = getInStorageOtherBean(context);
        bean.setInStorageNumber(inStorageNumber);
        saveInStorageOtherBean(context, bean);
    }

    public static void updateTenderInStorageNumber(Context context, String inStorageNumber) {
        InStorageTenderOverviewBean bean = getInStorageTenderOverviewBean(context);
        bean.getData().setInStorageNumber(inStorageNumber);
        saveInStorageTenderOverviewBean(context, bean);
    }

    public static boolean checkReceiveItem(InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean receiveInStorageItem) {
        List<InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean.BatchBean> batchList = receiveInStorageItem.getBatch();
        for (int j = 0; j < batchList.size(); j++) {
            InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean.BatchBean batchBean = batchList.get(j);
            if (REQUIRED_TRUE.equals(batchBean.getRequired())) {
                if (TextUtils.isEmpty(batchBean.getText()) && TextUtils.isEmpty(batchBean.getValue())) {
                    return false;
                }
            }
        }
        return true;
    }

    //检查免检入库行项目是否填完
    public static boolean checkFreeItem(InStorageFreeOverviewBean.DataBean.FreeInStorageListBean freeInStorageItem) {
        if (TextUtils.isEmpty(freeInStorageItem.getInStorageNumber())) {
            return false;
        } else {
            if (Double.parseDouble(freeInStorageItem.getInStorageNumber()) == 0) {
                return false;
            }
        }

        List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean.BatchBean> batchList = freeInStorageItem.getBatch();
        for (int j = 0; j < batchList.size(); j++) {
            InStorageFreeOverviewBean.DataBean.FreeInStorageListBean.BatchBean batchBean = batchList.get(j);
            if (REQUIRED_TRUE.equals(batchBean.getRequired())) {
                if (TextUtils.isEmpty(batchBean.getText()) && TextUtils.isEmpty(batchBean.getValue())) {
                    return false;
                }
            }
        }
        return true;
    }

    //检查招采入库行项目是否填完
    public static boolean checkTenderItem(InStorageTenderOverviewBean.DataBean.FreeInStorageListBean tenderInStorageItem) {
        if (TextUtils.isEmpty(tenderInStorageItem.getInStorageNumber())) {
            return false;
        } else {
            if (Double.parseDouble(tenderInStorageItem.getInStorageNumber()) == 0) {
                return false;
            }
        }

        List<InStorageTenderOverviewBean.DataBean.FreeInStorageListBean.BatchBean> batchList = tenderInStorageItem.getBatch();
        for (int j = 0; j < batchList.size(); j++) {
            InStorageTenderOverviewBean.DataBean.FreeInStorageListBean.BatchBean batchBean = batchList.get(j);
            if (REQUIRED_TRUE.equals(batchBean.getRequired())) {
                if (TextUtils.isEmpty(batchBean.getText()) && TextUtils.isEmpty(batchBean.getValue())) {
                    return false;
                }
            }
        }
        return true;
    }

    public static boolean checkOtherItem(InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean otherInStorageItem) {
        if (TextUtils.isEmpty(otherInStorageItem.getInStorageNumber())) {
            return false;
        } else {
            if (Double.parseDouble(otherInStorageItem.getInStorageNumber()) == 0) {
                return false;
            }
        }

        List<InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean.BatchBean> batchList = otherInStorageItem.getBatch();
        for (int j = 0; j < batchList.size(); j++) {
            InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean.BatchBean batchBean = batchList.get(j);
            if (REQUIRED_TRUE.equals(batchBean.getRequired())) {
                if (TextUtils.isEmpty(batchBean.getText()) && TextUtils.isEmpty(batchBean.getValue())) {
                    return false;
                }
            }
        }
        return true;
    }

    //获取验收入库行项目概览
    public static List<OverviewAdapter.OverviewBean> getOverViewBeanWithReceiveInSorageList(List<InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean> materielList) {
        List<OverviewAdapter.OverviewBean> resultList = new ArrayList<>();
        for (int i = 0; i < materielList.size(); i++) {
            InStorageReceiveOverviewBean.DataBean.ReceiveInStorageListBean materielItem = materielList.get(i);
            if (!TextUtils.isEmpty(materielItem.getInStorageNumber())) {
                OverviewAdapter.OverviewBean overItem = new OverviewAdapter.OverviewBean();
                overItem.setInfo(materielItem.getMaterielDescription());
                overItem.setNumber(materielItem.getRealInStorageNumber() + materielItem.getUnit());
                resultList.add(overItem);
            }
        }
        return resultList;
    }

    //获取免检入库行项目概览
    public static List<OverviewAdapter.OverviewBean> getOverViewBeanWithFreeInSorageList(List<InStorageFreeOverviewBean.DataBean.FreeInStorageListBean> materielList) {
        List<OverviewAdapter.OverviewBean> resultList = new ArrayList<>();
        for (int i = 0; i < materielList.size(); i++) {
            InStorageFreeOverviewBean.DataBean.FreeInStorageListBean materielItem = materielList.get(i);
            if (!TextUtils.isEmpty(materielItem.getInStorageNumber())) {
                OverviewAdapter.OverviewBean overItem = new OverviewAdapter.OverviewBean();
                overItem.setInfo(materielItem.getMaterielDescription());
                overItem.setNumber(materielItem.getInStorageNumber() + materielItem.getUnit());
                resultList.add(overItem);
            }
        }
        return resultList;
    }

    //获取其他入库行项目概览
    public static List<OverviewAdapter.OverviewBean> getOverViewBeanWithOtherInSorageList(List<InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean> materielList) {
        List<OverviewAdapter.OverviewBean> resultList = new ArrayList<>();
        for (int i = 0; i < materielList.size(); i++) {
            InStorageOtherMaterielOverviewBean.DataBean.MaterielListBean materielItem = materielList.get(i);
            if (!TextUtils.isEmpty(materielItem.getInStorageNumber())) {
                OverviewAdapter.OverviewBean overItem = new OverviewAdapter.OverviewBean();
                overItem.setInfo(materielItem.getMaterielDescription());
                overItem.setNumber(materielItem.getInStorageNumber() + materielItem.getUnit());
                resultList.add(overItem);
            }
        }
        return resultList;
    }

    //获取招采入库行项目概览
    public static List<OverviewAdapter.OverviewBean> getOverViewBeanWithTenderInSorageList(List<InStorageTenderOverviewBean.DataBean.FreeInStorageListBean> materielList) {
        List<OverviewAdapter.OverviewBean> resultList = new ArrayList<>();
        for (int i = 0; i < materielList.size(); i++) {
            InStorageTenderOverviewBean.DataBean.FreeInStorageListBean materielItem = materielList.get(i);
            if (!TextUtils.isEmpty(materielItem.getInStorageNumber())) {
                OverviewAdapter.OverviewBean overItem = new OverviewAdapter.OverviewBean();
                overItem.setInfo(materielItem.getMaterielDescription());
                overItem.setNumber(materielItem.getInStorageNumber() + materielItem.getUnit());
                resultList.add(overItem);
            }
        }
        return resultList;
    }

}
